/*
    能发送异步ajax请求的函数模块
    封装axios库
*/

import axios from 'axios'
import Cookies from 'js-cookie'
import { webApi } from '../utils'

axios.defaults.baseURL = webApi

export default function ajax(url, type='get', isToken=false, params={}, data={}) {
    if(isToken) {
        return axios({
            method: type,
            url,
            headers: {
                Authorization: `Bearer ${Cookies.get('answerToken')}`
                // Authorization: `Bearer ${localStorage.getItem('answerToken')}`
            },
            params,
            data
        })
    }

    return axios({
        method: type,
        url,
        params,
        data
    })
}